import { defineStore } from "pinia";

interface VisitorState {
  selectedVisitor: {
    username: string;
    digitalFingerprint: string;
    realName?: string;
    lastTime?: string;
    status?: string;
  };
  highlightedVisitor: string | null;
  customersData: Array<any>;
}

export const useVisitorStore = defineStore({
  id: "visitor",
  state: (): VisitorState => ({
    selectedVisitor: {
      username: "",
      digitalFingerprint: "",
      realName: "",
      lastTime: "",
      status: "",
    },
    highlightedVisitor: null,
    customersData: [],
  }),
  actions: {
    setSelectedVisitor(visitor: any) {
      this.selectedVisitor = visitor;
    },
    setHighlightedVisitor(visitorId: string) {
      this.highlightedVisitor = visitorId;
    },
    setCustomersData(data: Array<any>) {
      this.customersData = data;
    },
  },

  
  getters: {
    // 添加一个 getter 来获取显示名称
    visitorDisplayName: (state): string => {
      const { realName, digitalFingerprint } = state.selectedVisitor;
      if (realName) {
        return `${realName} (${digitalFingerprint})`;
      }
      return digitalFingerprint || '未选择访客';
    }
  }
});

export default useVisitorStore;
